<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>结清记录</title>
    <jsp:include page="../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
    <div tabid="tabA" title="结清记录" lselected="true">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">订单号</div>
                    <div class="field">
                        <input name="orderId" id="orderId" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="contractNo" id="contractNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">流程单号</div>
                    <div class="field">
                        <input name="procNo" id="procNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">创建时间</div>
                    <div class="field">
                        <input ligerui="width: 82" name="crtTmMin" id="crtTmMin" type="text" class="ui-datepicker" value="">
                        &nbsp;-
                        <input ligerui="width: 82" name="crtTmMax" id="crtTmMax" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">更新时间</div>
                    <div class="field">
                        <input ligerui="width: 82" name="mdfTmMin" id="mdfTmMin" type="text" class="ui-datepicker" value="">
                        &nbsp;-
                        <input ligerui="width: 82" name="mdfTmMax" id="mdfTmMax" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">姓名</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">订单状态</div>
                    <div class="field">
                        <input name="stsCd" id="stsCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">手机号</div>
                    <div class="field">
                        <input name="cstPhone" id="cstPhone" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">是否需退款</div>
                    <div class="field">
                        <input name="isRefund" id="isRefund" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">结清来源</div>
                    <div class="field">
                        <input name="stlSource" id="stlSource" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round"></i>清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>

    <div id="ligergrid1" class="sq-grid"></div>
    </div>

    <div tabid="tabB" title="自动退款记录" id="tabBId">
        <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
    </div>
    </div>
</div>

<script type="text/javascript">
    var basePath = '<%=path%>';
    var grid = null, pageInTab = null;
    var callback = null;
    $(function () {
        $("#stlSource").ligerComboBox({
            data:[
                {id:'1', text:'狮桥在线APP'},
                {id:'2', text:'资管结清'},
                {id:'3', text:'业务系统'}
            ],
            value: '1',
        });

        grid = $("#ligergrid1").ligerGrid({
            url: basePath + '/settlement/initList.do',
            parms:{stlSource:liger.get("stlSource").getValue()},
            method: 'get',
            columns: [
                {display: '订单号', name: 'id', minWidth: 140, align: 'center', enabledSort: false},
                {display: '支付表号', name: 'paySchNo', width: 190, align: 'center', enabledSort: false},
                {display: '流程单号', name: 'procNo', width: 170, align: 'left', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '<a href="javascript:commShowFlow(' + index + ')">' + value + '</a>';
                    }
                },
                {display: '客户手机', name: 'cstPhone', minWidth: 100, align: 'center', enabledSort: false},
                {display: '结清客户', name: 'cstNm', width: 100, align: 'center', enabledSort: false},
                /*{display: '是否退款', name: 'isRefundNm', width: 80, align: 'center', enabledSort: false},*/
                {display: '结清类型', name: 'typeCd', width: 90, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return value == "1" ? "正常结清" : value == "2" ? "提前结清" : "";
                    }
                },
                {display: '订单状态', name: 'stsCdNm', width: 100, align: 'center', enabledSort: false},
                {display: '结清金额(元)', name: 'estimateAmt', width: 90, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return formatAmt(value);
                    }
                },
                {display: '审批金额(元)', name: 'realAmt', width: 90, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return formatAmt(value);
                    }
                },
                {display: '创建时间', name: 'crtTm', width: 130, align: 'center', enabledSort: false,render:renderDate2},
                {display: '更新时间', name: 'mdfTmNm', width: 130, align: 'center', enabledSort: false},
                {display: '支付超时时间', name: 'overtime', minWidth: 130, align: 'left', enabledSort: false,render:renderDate2},
                {
                    display: '订单历程',
                    minWidth: 200,
                    render: function (rowdata, rowindex, value) {
                        var other= "";
                        other+='<a class="sq-button-hasicon" href="javascript:;" onclick="historyFlow(event';
                        other+=",'"+rowdata.id+"'";
                        other+=",'ligergrid1'";
                        other+=")\"><i class=\"sqBtnIco_41\"></i>"+'订单历程'+"</a>";

                        if (rowdata.stlSource == '2') {
                            other+='<a class="sq-button-hasicon" href="javascript:;" onclick="lookTriple(';
                            other+="'"+rowdata.id+"'";
                            other+=")\"><i class=\"sqBtnIco_35\"></i>"+'三方结清'+"</a>";
                        }

                        return other;
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            detail: {
                height: 'auto',
                onShowDetail: showChildren
            },
            frozen:false
        });
        grid.setHeight(100);


        //结清申请记录状态
        $("#stsCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("stsCd").setData(${stsCdList});

        //是否需退款
        $("#isRefund").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("isRefund").setData(${isRefundList});



        $("#searchBar").ligerForm();
        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "*Cd": " ",
                "stsCd_val":" ",
                "isRefund_val":" ",
                "stlSource":""
            });
            $("#stsCd_val").val("");
            $("#isRefund_val").val("");
        });
        
        callback = function () {
            grid.reload();
        };

        initTab();
    });

    function commShowFlow(rowindex) {
        var rowdata = grid.getRow(rowindex);
        var _pInstId = rowdata.procId;
        /*
        var _formUrl = "";
        if (rowdata.stlSource == '2') {
            // 资管
            _formUrl = "/project/financialInst/showZGSettlePage.do?bankAct=1-1-1-1@@processInstanceId=" + _pInstId + "@@paySchId=";
        } else if (rowdata.stlSource == '1') {
            if (rowdata.typeCd == '1') {
                _formUrl = "/project/prjprdpayschm/settleAddFeePage.do?isDetail=1@@processInstanceId=" + _pInstId + "@@paySchId=";
        }
            if (rowdata.typeCd == '2') {
                _formUrl = "/project/prjprdpayschm/addPreSettleFeePage.do?isDetail=1@@processInstanceId=" + _pInstId + "@@paySchId=";
            }
        }
        if (_formUrl == "") {
            top.$.ligerDialog.SQalert({content: "未知的结清流程，无法查看！", SQ_type: "warning"});
            return;
        }*/
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {procId: _pInstId, type: "1"},
            url: basePath + '/settlement/queryFlowData.do',
            success: function (msg) {
                if (msg.success == 1) {
                    var params = "?pInsId=" + _pInstId + "&status=" + msg.data.audStsCd + "&businessKey=" + msg.data.dataId + "&formUrl=" + msg.data.formUrl;
                    Add_navTab('tab_settle_look_flow_' + _pInstId, msg.data.pno, basePath + "/flow/flow/toFlowShowPageFowBus.do" + params);
                } else {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //订单历程
    function historyFlow(event, _id, grid){
        $.ligerDialog.SQopen({
            width: 850,
            height:480,
            title : '订单历程',
            url: basePath + '/settlement/toFlowListPage.do?id='+_id
        });
    }

    // 三方结清调用记录
    function lookTriple(id) {
        $.ligerDialog.SQopen({
            width: 850,
            height: 480,
            title: '三方结清调用记录',
            url: basePath + '/settle/triple/toListPage.do?applyId=' + id
        });
    }

    /**
     * 展开List
     * @param row
     * @param detailPanel
     * @param callback
     */
    function showChildren(row, detailPanel, callback) {
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        detailGrid = $(gridBox).ligerGrid({
            url: basePath + '/settlement/capFundInitList.do?id=' + row.id,
            method: 'get',
            columns: [
                { display: '资金编号', name: 'code', width: 150, align: 'center'},
                {
                    display: '付款金额', name: 'amount', width: 110, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.amount / 100);
                    }
                },
                { display: '来款账号', name: 'comeCode', width: 150, enabledSort:true},
                { display: '来款银行', name: 'comeBankName', width: 150, enabledSort:true},
                { display: '收款账号', name: 'acceptCode', width: 150, enabledSort:true},
                { display: '资金用途', name: 'capTypCdNm', width: 150, enabledSort:true},
                { display: '资金状态', name: 'fundStatusCdNm', width: 150, enabledSort:true},
                { display: '付款时间', name: 'crtTm', width: 150, align: 'center', enabledSort:true, render:renderDate2}
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }

    //初始化Tab页签
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                switch (tabid) {
                    case "tabB":
                        if (pageInTab.getTabItemSrc(tabid) == "") {
                            pageInTab.setTabItemSrc(tabid, basePath + "/settlement/refund/toRefundListPage.do");
                        }
                        break;
                }
                SetIframe_height();
            }
        });
    }

    function formatAmt(value) {
        if (StringUtils.isEmpty(value)) {
            return '———';
        } else {
            if (value > 0) {
                return '<font color="green">&yen;' + FormatMoney(value / 100) + '</font>';
            } else if (value == 0) {
                return '&yen;' + FormatMoney(value / 100);
            } else {
                return '<font color="red">-&yen;' + FormatMoney(Math.abs(value) / 100) + '</font>';
            }
        }
    }

    //格式化时间
    function renderDate2(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

</script>

</body>
</html>
